# import datetime
from enum import Enum

from tortoise import fields, models


class BreakReason(str, Enum):
    VACATION = "vacation"
    SICK_LEAVE = "sick_leave"
    PERSONAL = "personal"
    MATERNITY_LEAVE = "maternity_leave"
    PATERNITY_LEAVE = "paternity_leave"
    OTHER = "other"


class BreakStatus(str, Enum):
    REQUESTED = "requested"
    APPROVED = "approved"
    REJECTED = "rejected"


class ShiftStatus(str, Enum):
    REQUESTED = "requested"
    APPROVED = "approved"
    REJECTED = "rejected"


class Break(models.Model):
    start_inclusive = fields.DateField()
    end_inclusive = fields.DateField()
    status = fields.CharEnumField(BreakStatus, default=BreakStatus.REQUESTED)
    reason = fields.CharEnumField(BreakReason, default=BreakReason.OTHER)
    doctor: fields.ForeignKeyRelation["models.Doctor"] = fields.ForeignKeyField("models.Doctor", related_name="breaks")
    # last_edited_by: fields.ForeignKeyRelation["models.User"] = fields.ForeignKeyField("models.User", null=True)


class Shift(models.Model):
    date = fields.DateField()
    doctor: fields.ForeignKeyRelation["models.Doctor"] = fields.ForeignKeyField("models.Doctor", related_name="shifts")
    start_time = fields.TimeField()
    end_time = fields.TimeField()
    break_time = fields.TimeDeltaField()
    status = fields.CharEnumField(ShiftStatus, default=ShiftStatus.REQUESTED)
    # last_edited_by: fields.ForeignKeyRelation["models.User"] = fields.ForeignKeyField("models.User", null=True)

    # def working_hours(self) -> int:
    #     start = datetime.datetime.combine(self.date, self.start_time)
    #     end = datetime.datetime.combine(self.date, self.end_time)
    #     break_time = datetime.timedelta(seconds=self.break_time.seconds)
    #     if self.end_time < self.start_time:
    #         end += datetime.timedelta(days=1)

    #     return int((end - start - break_time).total_seconds() / 3600)

    # class PydanticMeta:
    #     computed = ["work_time"]
